package java6699.lesson12;

import java.util.Random;
import java.util.stream.IntStream;

/**
 * @program: java_zzx
 * @description:
 * @author: zzx
 * @create: 2022-11-20 12:16
 **/
public class SimpleStream6699 {
    public static void main(String[] args) {
        Random random = new Random();
        int number = IntStream.generate(() -> random.nextInt(61))
                .limit(40)//整型流随机生成一组40个[0,60]的整数
                .distinct()//排除重复值
                .filter(SimpleStream6699::isSushu)//过滤出素数
                .sorted()//从小到大排序
                .peek(n->System.out.print(n+" "))//输出最后结果
                .sum();//求和
        System.out.print("="+number);
    }
    //判断是否未素数
    private static boolean isSushu(int number) {
        if (number == 2) {
            return true;
        }else if (number ==1||number%2 == 0) {
            return false;
        }else {
            for (int i = 3; i < number; i++) {
                if (number % i == 0) {
                    return false;
                }
            }
            return true;
        }
    }
}
